
CityMainPlayer = Class("")

function CityMainPlayer:InitModel()
    --第一次 随机一次人物形象
    local random = GetPlayerPrefs("FirstRandomRole")
    if random ~= "1" then
        if logicMgr.MapManager.getMapId() >= dataTable.getDataTableByStringId("t_global","136","f_int_value") then
            roleInfoHandler.SendReqModifyPicMessage(logicMgr.SkinManager.getHeroSkinId(HeroManager.GetRandomOwnerHeroModelId()))
            SetPlayerPrefs("FirstRandomRole","1")
            return
        end
    end
    local heroID = logicMgr.HeroManager.GetRoleHeadID()
    if CurPayerShowID == heroID then
        return
    end
    CurPayerShowID = heroID

    local heroInfo = dataTable.getRow("t_hero", heroID)
    local modelName = nil
    if heroInfo then
        modelName = heroInfo.f_HeroModel
    end
    if(MainChrSpine.name~=nil)then
        if(MainChrSpine.name==modelName)then
            --local nameObj=MainChrObj.obj.transform:Find("Attachs/Name").gameObject;
            --nameObj:GetComponent("TextMeshPro").text=logicMgr.HeroManager.GetRoleInfo().name;
            return;
        end
    end

    local isFirst = true
    if MainChrObj then
        destroy(MainChrObj)
        MainChrObj = nil

        isFirst = false
    end

    local path = HeroManager.GetHeroDrawingRolePath(heroInfo.f_HeroID)

    resMgr:LoadModelPrefab(path,function(go)
        if isFirst then
            ---@type GComponent
            this.MainChrSpine.obj=newGComponent("HeroPos","UICity")
            this.MainChrSpine.obj.visible = true
            --this.MainChrSpine.obj.pivotX = 0.5
            --this.MainChrSpine.obj.pivotY = 1
            --this.MainChrSpine.obj.pivotAsAnchor = true
            map:AddChild(MainChrSpine.obj)
        end
        MainChrObj = newObject(go);
        MainChrObj.name="MyHeroObj";
        MainChrObj:SetActive(true)
        MainChrSpine.obj.onClick:Add(function ()
            --主城点击小人
            local _index = Mathf.Random(22,23)
            local _tag =  AudioManager.InteractionTagTable[_index].Tag
            AudioManager.PlayInteractionVoice(this.CurPayerShowID,0,_tag)
        end)
        MainChrObj:AddComponent(TCanvas)
        MainChrObj:AddComponent(TChangeSortingOrder)
        if MainChrSpine.wrapper == nil then
            MainChrSpine.wrapper = GoWrapper.New()
        end
        MainChrSpine.wrapper.wrapTarget = MainChrObj
        MainChrSpine.obj:GetChild("model"):SetNativeObject(MainChrSpine.wrapper)
        HERO_POS_Y = math.random(1030,1420);
        MainChrSpine.obj:SetXY((HeroLocaltionPos[NowCityArea]),HERO_POS_Y)
        Util.Lua_SetLocalPositionXYZ(MainChrObj.transform,0,0,0);
        Util.Lua_SetLocalScaleXYZ(MainChrObj.transform,88,88,88)

        local _titleList = logicMgr.TitleManager.GetTitleData().showList
        local titleItem =  MainChrSpine.obj:GetChild("Badge");
        if _titleList and _titleList[1] then
            local titleId = _titleList[1]
            titleItem.visible = true;
            titleItem:GetController("show").selectedIndex = 1;
            titleItem:GetChild("icon").url = "ui://ICONAtlas/".. G.dataTable["t_medal"][tostring(titleId)].f_MedalPic;
        else
            titleItem.visible = false;
            titleItem:GetController("show").selectedIndex = 0;
        end
        MainChrSpine.obj.name = logicMgr.HeroManager.GetRoleInfo().playerId;
        MainChrSpine.modelName=modelName;
        MainChrObj.gameObject.layer=5;
        local aniObj=MainChrObj.transform:Find("Animation").gameObject;
        aniObj.layer=5;
        aniObj.transform.localEulerAngles=Vector3(0,0,0);
        MainChrSpine.animaObj=aniObj;
        local nameHead = MainChrSpine.obj:GetChild("nameHead");
        --nameHead.y =nameHead.y -90;
        local textMeshPro = MainChrSpine.obj:GetChild("Name");
        textMeshPro.text= string.TextColor(logicMgr.HeroManager.GetRoleInfo().name,"#9BDBFF");
        --textMeshPro.color = Color(155/255,219/255,1,1) --#9BDBFF

        --skin
        --local skinName = (G.dataTable["t_roleconfig"][modelName] or {}).skin;
        --if skinName ~= nil and skinName ~= '' then
        --             (aniObj, skinName);
        --end
        logicMgr.EquipManager.setWeaponSkin(aniObj, heroID);

        Util.PlayAction(aniObj,this.getAnimationName(MainChrSpine.modelName,"idleFree"));

        this.OrderOtherCityPlayer()
        this.showMyPetModel()
    end)
end